package com.utils;

import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.os.Environment;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiObjectNotFoundException;
import android.support.test.uiautomator.UiSelector;
import android.util.Base64;
import android.util.Log;

import com.entity.PointBean;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import com.show.api.ShowApiRequest;
import com.show.api.util.StringUtils;
import com.yh.tess.constant.ParseImage;

import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import sun.misc.BASE64Encoder;

import static android.os.SystemClock.sleep;
import static com.utils.ChatClient.CODE_TIMER;
import static com.utils.ChatClient.DmtAppid;
import static com.utils.ChatClient.DmtSoftkey;
import static com.utils.ChatClient.DmtUsername;
import static com.utils.ChatClient.DmtUserpwd;
import static com.utils.ChatClient.addWorkTime;
import static com.utils.ChatClient.getCodeS;
import static com.utils.ChatClient.msg;
import static com.utils.ChatClient.pointBeansList;

/**
 * Created by Administrator on 2017/5/2.
 */

public class ImageView {
    // 识别图片的路径
    private String IMAGE_PATH = "/storage/emulated/0/Pictures/0000.png";


    public static Bitmap getImage1(int left, int top, int right, int bottom, int width, int height) {
        Rect rect = new Rect(left, top, right, bottom);//上下左右
        LogToFile.d("------截取全屏-------", "-------截取全屏-------");
        String filepath = "/storage/emulated/0/Pictures/0000.png";
        File file = new File(filepath);
        UiDevice.getInstance().takeScreenshot(file);//截图
        return cutImage1(rect, filepath, 0);
    }

    /**
     * 图片验证码
     *
     * @param objectResourceId
     * @throws UiObjectNotFoundException
     */
    public static String getImage(String objectResourceId, String bankName) throws Exception {
        sleep(1000);
        while (true) {
            sleep(2000);
            UiObject uiObject = findByResourceId(objectResourceId);
            LogToFile.d("------图片识别控件-------", "-------图片识别控件-------");
            if (uiObject.exists()) {
                LogToFile.d("------找到图片识别控件-------", "-------找到图片识别控件-------");
                Rect rect = uiObject.getBounds();
                File sd = Environment.getExternalStorageDirectory();
                String path = sd.getPath();//获得手机内存storage的位置
                String filepath = path + "/0000.png";
                File file = new File(filepath);
                UiDevice.getInstance().takeScreenshot(file);
                return cutImage(rect, filepath, 1, bankName);
            }
        }
    }

    // 通过ID查找
    public static UiObject findByResourceId(String text) {
        UiObject appBtn = new UiObject(new UiSelector().resourceId(text));
        return appBtn;
    }

    /**
     * @param rect
     * @param filePath:图片路径
     * @param spotImg：0：识别图片，1：图片验证码识别
     * @return
     */
    public static String cutImage(Rect rect, String filePath, int spotImg, String bankName) {
        Bitmap m = BitmapFactory.decodeFile(filePath);
        m = Bitmap.createBitmap(m, rect.left, rect.top, rect.width(), rect.height());//获取图像
        m.getRowBytes();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        m.compress(Bitmap.CompressFormat.PNG, 100, bos);//压缩图片

        byte[] data = bos.toByteArray();//转换成字节
        //        BASE64Encoder encoder = new BASE64Encoder();
        String img = new String(Base64.encodeToString(data, Base64.DEFAULT));//base64编码
        Log.d("----图片识别码----", "-----图片识别码------" + img);
        //        String img = new String(encoder.encode((data)));//base64编码
        if (spotImg == 0) {
            return saveImg(img);
        } else {
            return getCode(data, bankName);
        }
    }


    /**
     * 截图转Byte字节数组
     *
     * @param rect
     * @param filePath
     * @param s
     * @return
     * @throws Exception
     */
    public static Bitmap cutImage1(Rect rect, String filePath, int s) {
        Bitmap m = BitmapFactory.decodeFile(filePath);
        LogToFile.d("截图范围", "left:" + rect.left + ",top:" + rect.top + ",right:" + rect.right + ",bottom:" + rect.bottom + ",width:" + rect
                .width() + ",height:" + rect.height());
        LogToFile.d("图片范围", "Bitmap_width:" + m.getWidth() + ",Bitmap_height:" + m.getHeight());
        m = Bitmap.createBitmap(m, rect.left, rect.top, rect.width(), rect.height());//获取图像
        m.getRowBytes();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        m.compress(Bitmap.CompressFormat.PNG, 100, bos);//压缩图片

        byte[] data = bos.toByteArray();//转换成字节
        String img = new String(Base64.encodeToString(data, Base64.DEFAULT));//base64编码
        return saveImg1(img);
    }


    /**
     * 识别图形验证码
     *
     * @return
     * @throws IOException
     */
    public static String getCode(byte[] data, String bankName) {
        //        BASE64Encoder encoder = new BASE64Encoder();
        String base64string = new String(Base64.encodeToString(data, Base64.DEFAULT));//base64编码
        //        String base64string0 = new String(encoder.encode((data)));//base64编码
        addWorkTime(ChatClient.overtime_10);
        String name = "/storage/emulated/0/Pictures/code.png";
        Bitmap bitmap = stringtoBitmap(base64string);

        File file = new File(name);
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 60, fos);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String code = null;
        code = getCodeJH1(base64string);
        if (StringUtils.isEmpty(code)) {
            code = getCodeS(bankName);
        }
        return code;
    }

    public static String getCodeJH1(String base64string) {
        String appcode = null;
        String response = null;//返回识别码
        //阿里云APPCODE
        if (!StringUtils.isEmpty(ChatClient.AppCode)) {
            appcode = ChatClient.AppCode;
        } else {
            return response;
        }
        //API产品路径
        String requestUrl = "https://codevirify.market.alicloudapi.com/icredit_ai_image/verify_code/v1";
        Map<String, String> headers = new HashMap();
        headers.put("Authorization", "APPCODE " + appcode);
        //根据API的要求，定义相对应的Content-Type
        headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
        Map<String, String> bodys = new HashMap();
        bodys.put("IMAGE", base64string);
        bodys.put("IMAGE_TYPE", "0");
        try {
            response = post(requestUrl, headers, bodys);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return response;
    }

    public static String post(String url, Map<String, String> headers, Map<String, String> body) throws IOException {
        HttpClient client = new HttpClient();
        PostMethod postMethod = new PostMethod(url);
        // 必须设置下面这个Header
        for (String key : headers.keySet()) {
            postMethod.addRequestHeader(key, headers.get(key));
        }

        List<NameValuePair> bodyPair = new ArrayList<>();
        for (String key : body.keySet()) {
            bodyPair.add(new NameValuePair(key, body.get(key)));
        }
        NameValuePair[] bodyKvs = new NameValuePair[body.size()];
        postMethod.setRequestBody(bodyPair.toArray(bodyKvs));

        int code = client.executeMethod(postMethod);
        String res = null;
        if (code == 200) {
            res = postMethod.getResponseBodyAsString();
            //{"VERIFY_CODE_STATUS": "艾科瑞特，让企业业绩长青", "VERIFY_CODE_E NTITY": {"VERIFY_CODE": "3M85"}}
            LogToFile.showLog("图片验证码返回", res);
            if (res.contains("VERIFY_CODE") && res.contains("艾科瑞特，让企业业绩长青")) {
                res = res.substring(res.length() - 7, res.length() - 3);
            }
        } else {
            LogToFile.showLog("图片验证码状态码", String.valueOf(code));
        }
        if (Util.isContainChinese(res)) {
            res = null;
        }
        return res;
    }

    /**
     * 图片识别
     *
     * @param str
     * @return
     */
    public static String saveImg(String str) {
        String fileName = "";
        if ("".equals(str)) {
            str = "iVBORw0KGgoAAAANSUhEUgAAAf4AAAFhCAYAAACRX8izAAAgAElEQVR4nO2dB3NcyZEwoTPSeu+d4u7//6kLreF6v6uz" +
                    "+r4cMbnF5gDkUngDYF5mRMcbDLDAzBuJ2VVdXf2Hv/1/LiIiImIX/NNNv4CIiIg4HYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidsS/3PQLiIhH+b//+7+Lv/3tbw9dHf/7v//74DHfA65zzOeO8Yc//OEwLnvs+Kd/+qeLf/7nf37oylh/LiLuDok" +
                    "/4haCsP/nf/7nIHnHf//3fz80+P6cEKwThXUiIIpagc/rOv7lX/7l4o9//OPFv/7rvz4YTADmJIDHEXF3SPwRtwzFvcr+r3/962H853/+5" +
                    "+H6X//1Xw+ifycHMyvA7/G6RuV8PeWtwNfxpz/96eKZZ555MJ599tnDZIDfyff5Pcd+f0TcXhJ/xC1EeSN3BrL/5ZdfLn7" +
                    "++efDlYH8zQpwXTME/A6eOybmy0RPRI/YHYj++eeff/B7+O/MIPA7+RtF/BF3i8QfcQtR2kT6SP/XX3+9+Omnny5+/PHHBwP5m" +
                    "/L3OicCXvldU/ym9RE70p7XNa3/wgsvPPQ7+Jl1/T8i7haJP2Ij5hq7a+5Kegp7RukK27T+HDPi57pG/OvvuI6I/7nnnjtE" +
                    "/HOQ8meCwDIAV4Y/PycS/q75O9eCwJYIIk5P4o/YiLlW75XInYG8fUxEP1P6XOda/nxs9O/Pran9terfsUb8azGf6/1Ke67xk+736lq" +
                    "/4r9q8PPrWIsJI+L0JP6IjbC4bq7BI/wffvjh4vvvvz9cGXMiYCQ/Re8wU4DwZ1X/3O63Pv5Hq/qJ1k3/G90fkzyZALMDXBkvvfTSYfA6" +
                    "+f3uCLAwsKLAiJsh8UdshBKea/CI/bvvvrv4+uuvD+Obb755sGbPGj4TAa5G/w6+Pla9f9X+/fn1ZE2zr3vyj+3jnwP5G/lb9f" +
                    "/iiy9evPzyy4erwncpgt/Df0PED0X8ETdL4o+4JlbBGukbpSNwpI74v/zyy4vPP//84osvvjh8zSAL8O233x4mATPtb7R/2d" +
                    "/ZmnWiMMXvQPqvvfbaxauvvvpg8N6BSJ+fIRtgtA9OANa/ExHbkvgjroG53971" +
                    "+rme7yDCN9p3WK3P1fV7MwTuw79NzB4D7uO3NoDv8bzvgwwHWQzeJ5Mc6wRc8+fxLAB0OSAitiPxR1wDrt9bcc8wdY" +
                    "/Uvbq2z9XHTg5IjfOYSYM1Aab0bwNz6cAUPvD63N9voyHeO++J98hkh4zAXAqY1zkZsLFQRGxH4o" +
                    "+4BhAh0kZ0pu4ZpO4RH1fGnBz42AzBTOvP6vyreu6fgtmwB3xtPnaCYqSP9FkOYFJDkR+9ALyyHPD6668/uPKeeZ4JgMWEEbEtiT/iGpgV" +
                    "+1999dVhDd+rg6+n3I8V7U3Z3wbpT3wdZiB83UwIjPTXrYAW/3l9++23L955550HBYzzdyB9CwAjYjsSf8TvZK2kZxjpEtUj+U8" +
                    "//fSwpk0B37179w5Xxrqv/7ak8X8PblN8HLMRkIN75DkDswUwVyYHZAZM+dfoJ2IbEn/EY1i3xdlgZw6r9B3I3hQ" +
                    "/siO6t1BvHqd7zswGRkJWhCUQontk7hbHWRfBMsCaLWgJIOL6SPwRj2HdE4/oLc5zzPQ+kT6PLegzyr1s3/25MtsViwV/Sp+vuT+MKf" +
                    "/ZD6C1/4jrJfFHXMGxtD7RO1JH7kiegfBtyONj0v9W6hvxz9957qx1CgxEb00AkmcSsEb8XN94443D/aJWoHX/iOsl8Uc8AVNiSBxhIf6" +
                    "//OUvhzEr9x1zL76V7/6ueT1nPCdg1gUofaJ40vhT/AwmStwvpf/KK6/c8LuIOC8Sf8QVKKwpcNL3iJ1InyK+//iP/ziI3977rGFz3YPYr" +
                    "+LYBEf5W6yH3N3pMPsYkN632x9dANnyN88VmIV/EfH7SPwRV2B0Ovfff" +
                    "/bZZxeffPLJoYiPtD6it2HNTOnH47HpD8JnQuXhQBb1uRuAycAs9qvgL+LpSfwRV2DVuel7Insq9on0ubKWj/g9Vc+jcuPJmOJH" +
                    "+HYq9ERAMgJE9tzX2e2P5xN/xNOR+COuwIhf4TtmUR/r/Uqfn7+N/fVvG/P+KH6EbwfD2bPfFsF0+uNnyACw3z8ino7EH3EFU/yk" +
                    "+FnPJ8XP1x64Q8Rvm91133o8Hu8dwme5hEnAlP6sseB5pE/f/4h4OhJ/xH1m5b4Sd8sZgifS//jjjx/s0XcPPz" +
                    "+T7J8OxT7vH3USM81vh0PX/kn1U+nPBGAt9qvgL+LxJP6I+yAYpDMHUT4RPrJ3yx7SR/Z8n0i0tP714rq" +
                    "/zX5mwZ8tfW3ray2Ao5P9Ih5P4o+4D+K3574d96b4TevzPdb0FX9cL4jftP8s+EP2iJ/BNj/T/k4EPBwoIq4m8UfcB/EjdCJ61/ARPyn" +
                    "+KX4mBESkyKmI//qZET/C9zRDxY/0GRT52RjJ0wAj4vEk/oj7GPEjftf0j6X6rUB3JP7rxYifz4MrUkf" +
                    "+Sp9mPlxJ84PLAHfxpMOImyDxx26Zwp77yRU/wnfLnmv7Nuk5NWsB27GiNp/z5+f1GOthQWtv/WOHCp1ikjML/vhMgMie9X4+B" +
                    "/byK34P8OHrxB/xZCT+2CXH5IbQETuCRzAetqPwiT5PKZcpbQRHahvJzavDr13ntiBuTgamtOfWQ6vmkavnC3BdzxrwehMZDj8flln4bIjweZ+8Z1L8VPqvr60K" +
                    "/4jjJP7YLVN+riVTrW8vftf1p/hPLT3lhcCJcGfb2vXK4GecADgp4L9do3UlPkVvv/w5eM6mOtY03ATu81f8Tm5476T+ea1T/Ek/4nISf+wSRWjEizQui" +
                    "/jt1Y8cTyX+dV+6KW0PrpnDSncr3N3aNtvezpMBfd/K3K2L7miYx+NaWQ/8N1Oop0r7e3Vixnvy1D8i/ddee+3w2mfHRE8EbAIQ8SiJP3aJaX6lv4qfQj4L" +
                    "+mbEe8qI/5j4ETsRLuvcDuRnH3vkz+TA7IAH3azr9bxfo3qkyZVMB+vovH/+exvogBG3Qj01M+J3EgBIn9e7RvxJP+JyEn/sEuU3I17Etw4iTNe3t" +
                    "+zBvxbjrev4yJw2tQy61jnmwTUWvZnynyfcreIne3FM/MeyCDzvaXhMBmyx6305xc4GX7P3h8e8HiYq9lyY7X5d4piTl4j4O4k/dslc0zetPY" +
                    "/YRYQeuDOluQVrVT7XNZVPlI/op/wVvdvcTPW7zs/VyH3K2UkPE4M58eFv2A7Xe4JYuSdeGU4UuPp4Fj1ucZ9mhsZKf/6uNRm8LrIzTAasezDrUVOfiIdJ" +
                    "/LFLTB1Puc0GPQhtRrRbRrXK3ggVaSPhV1999TBIZxvhK34Gkl4L/JT+HGtxnxJdK/hncZ9C597Yv8CmRqTWPavAPff+XlPsW9yrKX4e8/qI8l2i4LXx" +
                    "/t3aZ0vfiHiYxB+7xL78SB7Zs57vfn1EgvgU49b72Ffxuy8d4b/99tsX77777sWbb775kPQZTA7WLX5Wu88tfccK8mZho5ObuYXPzoQeUMS9IcPA3" +
                    "+Sxywfcw1mLsGXK3+UFO/XxGTFxYxLixI3Jj9K3JiIiHibxxy6ZqX6kgcwuS/XL1ql+9+AjLASL+JH+n//854v33nvvgfARMNd5Ot1lp9Q9aQOfta" +
                    "+BWQ7Ez6RI6btrwEife2VGwb+3Zap/HtN7LNVP5mNKv6Y+EY+S+GOXGOEiD+TlEbum+W0Ze4oKdpvQMOxH/8Ybbxyi/LfeeusQ9b" +
                    "/zzjsPqvcdp4hmeW3eA5sIWWjnLgjuGY9Nwyvm62bNuKyvgc+PTImn+LkkEBEPk/hjl1jgNvev34T0iU7tPOf2PNby33///YPskT/r/HOrHtGse+u3hgyETXLcxz" +
                    "/rAhxW1FsbcIpGP3NnhvIn+ne7YwcoRRwn8ccumdKYjWsU/9bSmKl4xf/6668/iPRJ8RPp87XiNytwU+K3e6CR/awJcFsd78dTDk+xxW/2X" +
                    "+Dvcx89T8F6gIh4mMQfu+SqiN+09amiRWSq+FnLR/qk+JkAzIh/rdQ/BS5DOEEh67D29Wfwc2YDkP4pWD9Dey9M8RfxRzxK4o9doryM+N3Pf6qIX2bET3SP9D" +
                    "/66KPDJIDiPobiP1a8tzVG/ExOZoHdjPYZU/rI9xTMz3Cm+hN/xNUk/tgls1+9+8GN9tdq/utkbt3jMZEyBWk2zkH+RPtzy56V9DfB3G0gvCZe26yHcHsk95G0Pz9" +
                    "/7Njf62Z+hkzeGDx28laqP+JREn/sEsU/K8On+Ldq2DO37HElkrYYzY58RPh24vPM+dsEkxUmI7xe5Mrr42q6nV4I1gLM5kfXfT/Xz3AWFzp5K" +
                    "+KPeJTEH7vkmDRmpLiVNDxsx3a6Fs5N8TN43hT7bWs5i/iZlJji5zVy/zzV0AwF35tNd66b2YFwin9mbRJ/xKMk/tglq/htU" +
                    "+u69VapfvfC22bXPvxu5zPinx35bpv4Z0c83gfZCVLsNNDhfZipcN1/y3bH8zO0m1/ij7iaxB+75LI0sf3gt5LVjPgRP9I8FvHfRCHfk2Kq33Q+g2j/iy" +
                    "++OLyP2d3P+7xVxD8/Q+6T4j9lL4aIu0bij12wFppZje6YJ/FtGaF6CI9b45A+8keWHrJzU4V8T4oFf2YvuF9MYngPdh6c7YS9p1vg77a6fxb1VdgXcZzEH2fP7D0" +
                    "/t6Mp/WNFaFuJ34h/pvmV/ikb8/yjzCyEEwCzGL4vf2brFr5madZDh4r2I46T+GMXrIJwH/oUxSr+rar6PTMe4c9o30r/286xpYf1fSH+WXzn0b3Xjel+dxY4kTPNn" +
                    "/wjHiXxx9kzpT9T+8cifn9+K4z4Z6qfK1+fsiPfdWD9AffrWMTvfWbNfYv3NTM58xyB9fOMiIdJ/LEL5lrw2nVuRv1bc0z8dz3V75o/4p/viygf6W/5vlb5n6JOI" +
                    "+Kuk/hjF8xz3OcBM6cSviBA0+KKcm7bu20V/E/KfF+zT4HLF1uKX/nDZUs3clfvb8R1kvjj7JmpftebZ6OeU0aHtuy1ul9RbinHUzDfl+J3MmN1/1bw" +
                    "+c1CwlnI6ZjLEsk/9k7ij7NnXeO/TeI/pSC35NiEZuv3NaN5P8M14l8/2+QfkfhjJ7i+P8XvOv8pU" +
                    "/1rZHwKQZ6CYxOamcnY6n1N8fM3jkX866Turt7jiOsi8cfZs0b8s7jvJiJ+5TgjYyv676qUFP+x97Vl7YJR/0z1H4v6XUa5q/c34jq5u4uKEXccJXRuMrrJVsNrq" +
                    "+Pb3Po44qZI/LEL1n/4b4N05zn157b17Cbez/xMHUT6ZlKSf8TfKdUfZ88q/FX6p5TB2hVwCvKuy//Ye9u6BfJln+VV0X7yj72T+GMXFPGfltsQ8R+L9JN" +
                    "+ROKPnXHb1nzPTfg3zfr5muqPiN9I/LEL1q1mN7V/fu0guG4rvKsTgWNNkmZnxC1T/VPyfp53eYdExNYk/jh7ju2dn3voZ0p4a" +
                    "/FO8dvLfjYTuuvin70S5pbJLd7XGtX7Gc/JXPKPeJTEH7tg7p9f+8jPfeZTFFvIyn3lRsWIf+0pcBe5qUzGlP/aD6EUf8RxEn+cPWvEj4gU/22K+M811X+KiN8JXBF" +
                    "/xONJ/LELlIMV9Ldxjf9cUv2njviPpflb44+4nMQfu2BGhkhoPT6W43G5zv7uiPi6MSL+61//evHzzz9f/Pjjj4crX" +
                    "/P8XUn1r1sRlT3v45dffrn46aefDleXMra4lzPF72f4zDPPPDSpS/4Rj5L44+wx5YsIZBb4KX/G2uv9uiNVfqeCRPjIamtBXjdrYx6GSxdT/L" +
                    "/++uuD97XVhGbWbXAvncDxuRb1Rxwn8ccumIVeyMCDZFZhICnYKjU9I34nHojyLkb8pvctVkTyip9JDeLn661OQJwRP/dxjfgr7os4TuKPs8eob1Z7K/014gfT/FsU" +
                    "+03xuxY9I/67IP5V+rNYcUb8PN46kzFT/UjfCVyp/ojLSfyxC9YKb7d+rWv8s0htC4yOkaKvC1ESHc/9/Gv72dvErOBX+giewfsw4p/HH28Z8Tt5Q" +
                    "/zPPvvsQ1s1b9u9i7gNJP7YJQoD4T/33HMXL7744kFYPO+a9RbScFKBlBA9V6LjH3744eKbb765+OKLLw6vRXkpNSYptwVev2l8rozPP//84uuvvz4UK" +
                    "/K1jXy27NzH5+Nn+Pzzzx/uG4PHPFe6P+I4t+dfk4gT4jr/FD9Rqml+pLyF+P39RMLKkL/7/fffH8T/5ZdfXrzwwguH14TAuJrOvi0gdCZJTFYYvHbEz+vna8S" +
                    "/NiXaSvzrZ/jSSy8dHhP9870i/ohHuT3/mkSckCkN0sPIlmHaeqs0sSlyHyPEVfyI6+WXX36Q8uc13iaQOuLnNX/11VeHYcQ/xW8NwKnEj" +
                    "/RnxE82IPFHPErij11yLNVPyt116q2iRde6Tfkj95nq53UwEeF5XiOvb6t6g6fFiP+77747TFQ+/fTTwxKFET/fm417tmzes6b614i/VH/EoyT+2CVGiwgCaSAMG" +
                    "+lw3Uoaa2MgHps2//bbbw/SssjQ10cmgte4nit/imj22J59Jkas5fN6Ef9nn332QPw87xa+LYUPTt78DMmSMLhfPFfEH3GcxB+7xGhaYbz++usPeucjfsRh" +
                    "+9fZpW4L+Lv8TUSqrNb2vYh0Hi60ZcHf/LvzMCGv9+7dO0T5XBlT+qb5t8Aqfic93AOyI0T6r7zyyuEzfO211x5E/Xy/iD/iURJ/7BKEgBgUP1JTwKxdMymY4t9K" +
                    "/ra75e8idJjb34xY+dpiP4Yd666b9X362liOcCB7onyurO0jfjIWduvbamliHr/r52d9Bp8h0kf+PE78EZeT+GOXzIifaBHRIX7X2hX/1sf0An8XaToJIFXu35p" +
                    "/34I/XjsZietm7b8PFvKxnk9GgntjxI/8ET/pfnsR2IHwuu/VehKfPRjWiJ/h5CjxRxwn8ccuQR5G/ETTfE0am8p0npvFYRapbdHJzwmH0ne9H" +
                    "+bJczzmdWxd8LdmNyzkIwuC4BH9sYh/Nh/aOtVv86W5I2Om+mcXv8Qf8SiJP3bJXCMGRILgLA4jYrSb3+xQtwUKE3nOFrQKzqjfyYfS89ChtehvXh/HnMjMrXc" +
                    "+ntsMjfQRvZE+EyWyAbMmYavMCO/XKn7uD58Rn5XV/Mifz8/jedvHH3GcxB+7xNP6EInr6W7rQx6vvvrqxRtvvHEQse1oHdfdfnYKU" +
                    "+GSMqdYDrGC3fJ4DtEiY2Sn4JSddQkzW3DZ31z32dttj2EDHv4WoncoeyYETJRM628le5lLMwyE/+abbz60pm" +
                    "+b3pklSfwRj5L4Y5fMPu9G0u4FJ3IkZYz4geI2hkfqboXyJHpW/Lwu5Ir0qQNQ+kgY8a+V/spvjpkxkNlr32yGJ+zNCn4E79q" +
                    "+V5YieG3cE5cptsZiPtP6TMzeeuutw2eE+Pns+P4q/oh4lMQfu8SI38dEzYrfiJ9o0nV1rohwK5msaXLEr/Rd90fCprW5IkGWKljP9oAae9Q7PJd+ytleAjO6V" +
                    "/oesmMPfgTPUPZ25uP1Mab4t5wA2MGQ96z033nnncNnNLfvmd4v2o+4nMQfu0Txu6aO2Geqn4gfybm1TgFv1b9/YqrfwjoF7na" +
                    "+eV3HPJ3OLADvcy3aswjP6J5hVoFBNI/o5ySAx3blm9mCU6f6V/HP7XtzMjevEfEbiT92ybGIcHaAQ/zIzkNm3HI3awJmN7vrYF3rn9XxiM" +
                    "/GQlasW9xmZz8zAPapdxngmPhnat+0PlLnPSJ8r0b1s4nPqVL7M3KfzZb4bBA" +
                    "/Y0b8Zjci4moSf8R9ECTiRC5IborSdXbki1xmxLvVITQTJwMIe60zcEcAklb6jJnq93d4nev6Dv57o3req6I3wj+F8MGll/keyMTYoIeiPobr+0x42rMf8eQk" +
                    "/oj7IBnFj+TspKcULa5zImBEft1V/peh+O0nYEW+0mdSYoQ/t7QdW+O3uE+pO6Hwd1nkZx2AE5xTMLcsWrtgpI/sGcrfJY65vTEiribxR9wHcSAaUseIh" +
                    "/Sxh9IofaJLu+fBPHBna/xbc+sdk49ZzDer2tfq9mPydwIwJwJu5ZvC3/qkvck8QMmlDKN9huLn6p7+mvVEPDmJP+I+pvqJ9JG+J8whfSrq2b+OhEy1I0W3y50q1W" +
                    "+anr9pw5/18JpjDX0u+51T5rN5z7yeomp/4nG7s+aCgr5jqX5b+HqNiMeT+CPu475" +
                    "+08yIjvVuhYNo2MsOTAbc5keEvHau20KSp4q4T806cXHiRebFRkoU8tmwh338fI9JQUT8fhJ/xGCNkJEQUT7CYQ2dLADCoZENKWaP0CX6np3wTrkEcJdxW+VcriDSR" +
                    "/iI/u233z4Mtu4xeJ5JwVZHEkfsgf7fE7Ew5Y/cqShH/Ejfk/HICPBz7rX3scsD8eR4YJJr9Uys3LL33nvvXbz//vsP9uwjfr6f+COenv7fE3GfNdr3IB" +
                    "/Ej9CtAbCQbJ5cZ9tfIOI/xbr/uaD4ubcM0viK/91337348MMPDxMA+xW4Zz8ino7EHzFY5a/4kRPCodCMaNNDc6j0R1YW3NniN56MuWffYj737Bvxf/TRR4frPI" +
                    "+giD/i6en/PRFHcAJgod+sNGefO1E+0if9zJWJgSn/9TCfIv/fWHcbcN/swc+kisI9Cym5MgEgvc/zc3tik6uIpyfxR1yBkmECoMCN" +
                    "/BGTbW2ZEDAZcAmAbMDa8KYJwMMV/O6iIMpH7O7Ptw8/0if6d2mlw3cirofEH3EFVp0rbb52q9ns52/zHI/UdU" +
                    "/5qffA33YUvp0F51G7pvZZ12cCwP2d7XiP9SmIiN9P4o+4ghnxKyzFj/TnQTpE+DzHqX7u8ZfE/3ecSLmFD6l74h6yR" +
                    "/wffPDBYSLAWMXv74iIpyfxR1yB4rffPUPxk9IHT+yjtz3SJ+0/I9Sq/H/De2lBn+JH8oqfKv557PA8gCfpR" +
                    "/zjJP6IK5gNeRyeYDdPsvP4WiYDRfqXs3Y3tAWxRwR7AuKccM2agLVFcUT8fhJ/xBUgJU+q89Q62vbSt//LL788jK+++uri888/v/jiiy8OFf5MBmzhu" +
                    "/bD3zuKHjxvgAJJ7qG7J7jPpvqt6GdCZZbA7Xz15o94OhJ/xBVYrEcUSn9+BpJC8sjewWQA6VPZb0W/kX/S/w0P/5mwPIL0gYkVEwEP4rEVMvAz/lyH8kQ8PYk" +
                    "/4gqM+BG+ckf0n3322UMDWc3U/3poT/wdI/55+h/3jkjfGgnuM/cb6fN9BE+Ub6bAryPi6Uj8EVdgxK/4ifbv3bt38emnn158/PHHh/HJJ58cfsYaANf5E" +
                    "/6jWOjo1UmAKX8K+Vg+mdK3lS9fE+nzM93biKcn8UfcZxbyeSV1r/BJ7yN9Inwec0If30dYFKet59rHcWYmBPm7JZIJExMortRQUNnPDglED6z3u5OCCcHaDKj9" +
                    "/RFPRuKPuI+tdkk5e0VASB7ZE+VP6ZOWRlRT9An/92Paf0b/ZFi4x6T0eY7PgjoL1/wVv0V+Humb+CMeT+KPuI/in1v1rNg3vU9aHyER5duudxV/8n9yvF" +
                    "+zEFLxu47P1zZL4vsInkyAfQAYNgaKiMeT+CPuM8VPNO82M1P8ruuT3neLH6PU/j/GLPTzSnQPrv0zEZhr/vTwd90f7PsfEY8n8Ufcx+57in9d20f8f" +
                    "/nLXw7ftx7AkfifHiv9TdPzGNG7tY+InskW0ifSR/qs99PO13V9uydGxONJ/LFLZmMdxY3QEQ3CtzkPa" +
                    "/rI3y1mduhbf8dWzDVrO9chwGMd7S47yOaydsFrin2dzMwofI6tmK/RIj7+Ho95b8ifZRYmYrTy5X1xSiIDbOzje57XiPiNxB" +
                    "+7ZbbhZZBeRi4U9Fm9zxXx30Qh35SXUe3sXOd1jjkpmJOB9TXPgjqFjmAZrKUfe8w4VQ3D2uiH18Hng/hJ8fNeeY4T" +
                    "/XgPHp7ker8Tooh4lMQfu0SxKDfFgvgt6GM9n6ifaF/xz8Y8/p4tWCN2D7ahcx3pbrvYITqvDCYDnn7nmCcFzi2H9hxg8JhMBsOshjUMPj/b7W753q8q" +
                    "+OOz4D1Zj8Hr4f0xGaC1r197qJL3LyJ+I/HHLlkPh0Eia8SP+HnMEgDfsxXv/B1bM6NXpI7kiWwRnVcmAl75/poFmCcL+pqVvgcLcR8QPu/R7oMMt83x35l" +
                    "+PwVzCcae/oif12M3RV6v0ifdz3PzHAD/24h4mMQfu0TxKz/78dOSd0b8fG1GwMj4VIV8c61" +
                    "+RvxWtVPc5tG1DCcCbnObh9ko0RlNz54FbplDrhbUTek7STrV8cJzkuLf5PPhdfNZkYHh9Rrp29d/ij/pR3Ji" +
                    "++0AABh1SURBVBwn8ccusYIfybl1D9kT4SN7vkYsRpGuhW/BsUK9mcpnWM2O7Lkypuwd/Ny6/r+KHxQ5snRig1DNbhj1ezCRg/vif+OEwf31W51G6O9zkuZzvBYL" +
                    "/tx94b3jXrgs0v7+iIdJ/LFLEB9iQ/rInmEFPzJBfAhtFr9tFekazStpRD8F72MjfB8jfScIc6JgJ7vHrfHPor2Z" +
                    "+fD4YbMgNitykjRPKvTxvE9b3KtZk2E0v267fOmllw4/631jWPMQEb+R+GOXePgO4kAanrI3xW/qeMrsuoU20/gzun/ttdcO4/XXXz8M9q0jfeXP1bT+PKd+yn6O" +
                    "+dpnun9mM4z850DqZkS4enYBg0jb9XcnSf7+LVD8vnbe79x+yf0AswJ8n8lRRDxM4o9dMiP+y8SvzLber2+ErvQRO6J" +
                    "/5513Lt59993DYA17Xc83jX3Z3v7L1rnXw4TmXv15QNHc4jgHKXX+Nlh0NwvptlgSWY/z5TH3zIjfSZD1ADzmPtXUJ+JREn/skhnxk+anKx+V/MrNiP8UleyzYl/xE" +
                    "+2//fbbFx999NHFn//854v33nvvIPs5+Hm47iK2OcGx4HEOJDsr7XkdCtbjdrdgNhByUkPET+aBSZMTHyYETp7m9sOI+DuJP86eY81qLFQzfc1w/ZoJwTxm9zpZi" +
                    "/iI1FmbpjKdLWlckT6iZxDp8xypfSYFHlPrGv7WMCFxMqLU3QmgVPkZ791c/z+2vHBdzJ0JTNL4/Nz1wL1C+jzPa3U3wsyEROyZxB9njxXhc" +
                    "+16Fqspf75WFq4lXzfKXnEjTbej0YVuXt94443DYEJAlG0NgHvzTwF/h7/pgTh8zb1xEsD3mBSQNSHyZniM7trm97rvp+J3ycbXw" +
                    "/3ks2QSovi9776n5B97JvHH2TO3glmxPovWZsTvFrWtxO8Z8hbjEaEidmT//vvvX3zwwQeHSN8e9GQDGKT2Z+X" +
                    "/qcTl5ATxOwnwfSh9XicV9H7PJZT14J3rhs8HqTNZ4+/wN3itFEPOSRw/M7MjtfKNvZP44+yxMGw26lkjficBNvXZqlGPkaetdmcDGqT/b//2b4d1/XV" +
                    "/vmvYs4jvFCh76xAsqlP6TEoQLe/F1rrcSwvtZnbgujHiV/p8trw2+zAofn7G1+MOhyL+2DOJP86eGfGTFj4mflP9/vxWWHxmtG+7WSP+f//3fz" +
                    "+MuQ9f2d8ETjLmWfes+TMx4XXb2pefsSESW+t4/euOgevGiF/pOzFaxe8a/0z3R+yZxB9nj3vU57G7rEUjfKv3T7Xty+Y8pvLdtkdBH+nyuUXvtq5F85pcAvC++Z6I" +
                    "/pnEKF4nWly32CGxtiHmb5jV8dwF9/O7p/+UNRIRt5HEH2ePKWiLwJC+J+7x3CnEr8CtOkeQpPcZiJ+vET/fV/yzV" +
                    "/9twqzF3FrHe2LJwvV17qu1E4CQeW4LlL4pf2s4pviddPC6bfQTsVcSf5w9c9uX+76PRfxbFfNNiPgRPBE+jXlI77NfH2GyXj4j/tsofZgRv+lzxY9wbX7Ee" +
                    "+VnzbZcN+vn5ZLOeuCSyxRIn/tbU5/YO4k/zh5T/Ub8N5HqV+Cm+hE/kf6HH354eEzKf6b6p/Rvm/xNk88dCqb6zaAoZUTsPvutMNVvMeEa8ZNFcWcCrzPxx95J" +
                    "/HH2zG1frvEzXIfme1vKYErcVL+d+ajk99Adhqn+24wR/3ydbuuzsc+M9Im83ep33cyo390biN81flsbe5TxVo2ZIu4SiT/OntnABykgo1nxvXWzHq8Me+0remRk" +
                    "+11T53cR0+i8H9fTibqRvl0HeX9bHt8L87P2mGGG3Ri3+qwj7hKJP84eI8HLZLDlnn2b7tiwB8krfiN9pKj4b3u0fxmKn/cDvBdT7bxfxT+7+W1RV2Fr5tmzwc" +
                    "/abETij72T+OPsWRv4TPFvKYN53C5iZ6xH63pmvJODuxzxe3iP6+nUUXCS34z4PfUPtrjna5fGU33WEXeJxB+74HER/xZY/OZxu8hwRvyK3z37p" +
                    "+zId90Y8St95EsjH9b9Z8S/5dG9cCy7M3v2J/6IxB87YEb8CMBuc/OUuVNE/PNIXWQ4m8rcddZiP7CHv+K3wG+elnjdHMvu8FkX8Uf8RuKPs2eKxjSwB/F4VO" +
                    "/WffmN+BXgTbbhPRVz4uP7tz8B93yL96/4jfqZ3M1ov618EYk/doLiRwCK3yrvrWQw+/Lb317x76FtrBMf378d82yty/3fgvn7zerMz7qIP/ZO4o+zZ0b8q" +
                    "/i3jvhnxOu2vT2Jf13qmGvwWzQmmj37/ayL+CMeJvHH2TNlMFP9poRPleqfEf9eU/1zj/1Wqf45yeNvnGKSF3GXSPxxtvgP/LGI3259W4pg9rQn4l3369" +
                    "+2VrzXzbH3bwS+5fufnzV/YxV/xN5J/HF2rF3h/Af/2Niie5x4BryRP9HvbT9y9zq5qffvRO/Un3fEXSHxx9kxz2efVd6nlkDivznxzyzPTPEn/YjEH2fG/Eff4T" +
                    "/+U/5rVmCrI3nngTa2711P3ztX5vv3vVvUuNX7Xz//Y597xN5J/HGWrP/4H0v7zp/diqsi3j1wU+//WLp/y0lexF0i8cfZcewEuJtY5zWqnfKbae69RPxrS+Kt3" +
                    "/+xz32r0wAj7iL7CDtiV0zhrOLxe6eS7lUSOnfW9z6vWxdVrv8bOPXnHnGbSfxxlqzR5k3+w7/1GfS3mWPyP3XGJeFHPEyp/jgr1mgPLpP/lMFWR8ReJr6t" +
                    "/uZt46aWWlbpX/a5R+yRIv44O1b5H0v33kSqf29R/1UTn1Ol+m/qc4+4zRTxx1ky/4G/bJ1fthLQup98PQ3w3OXve5zbKR2nivjXzz0iEn+cKav41" +
                    "+p6xtZbvKb01xMB93Au/GWtkrfsmb9me/ys97KTIuJJSPxx1hyL/OYBOVv2bjfanUfE7ul42PX9n+p43GOTvMQf8RuJP84O/nFHKrOYaxXBPCQGCfnfXCfHjojdY8R" +
                    "/6ve/RvvJP+JhEn+cJU+S6gelvwVXRfx7Eb9r+qX6I24PiT/Onssiftgy5TzXtzl//tdffz1cEeBl8r+rYlq3KTJ43wqfSY/vfesjctfPerYKvqv3N" +
                    "+I6Sfxx9qyH5XA+PAPcW75Fqp/fa6SP9BHQL7/88ogA10j0LsrJ6H6ej8D7dMLjMOuxVcZjPRjIz3ou79zF+xtxnST+OHtmxD9lMKvOt5CBaX5kZ8Sp+HnOqP" +
                    "+mOwteB/MkPN4XY5U+Yy3w24J5KJCf9Yz6I/ZO4o9dcOx42CndLZgRPzDRWCN+5Tc7Dd5FjPhnen+N+HnvTna2FL/3UvHv8VTEiKtI" +
                    "/HH2rMVeRoEKaKtI24p2xG9EPMWvBIHX5tr4XYz6ZyHjlP4q/2PH5F4nly3rKP+7nFWJuC4Sf+wCo/0//elPF88888xhKOa5te86UYY+5u8Z+f74448XP" +
                    "/zww8V333138cc//vEgJ66MuxiVOsHhvf30008XP//88+G98R55jPzJBCj7LcWv8Pmsn3322cNn7T3e6rOOuEsk/jh7lAH/+COB559//jBmRL6V+C0cdAKA+JH+t99" +
                    "+e/HFF19cvPTSSw9eDwPpW3h4l0DqSB/Z8958f1wRP1mAUxxQxL1mgsdnjfS5py+88MLhMc8l/ojEHztgymCK37Vovrel+OfjKf4vv" +
                    "/zy8DpeeeWVB0sOCuuuwb00ykf4jM8///zwPskArOKHrSL+VfwMxb/VZx1xl0j8cfbMiH/KwL3lW6b6V/Hz9xD/N998c4hESUdP6fPcXYT3YMSP9D" +
                    "/55JOHIn7u9amO451LOtxPPmvT/UX8EYk/dsAa8T/33HOHgai2jAKVnGl+/saM+Hkt/m1eB4JCoHeRmeonk/Hxxx8fJjcz4t/yXASxmr+IP+JyEn" +
                    "+cPTMKRPisqyMjC9G2lMGa2kaARMDff//9g0I+ReXr47r2mbfT4E0yJzLu1Xd89dVXB+E7+Jr3yCSHLMcpJjRW7FMj4ZIOn7V1FNzXxB+R" +
                    "+GMHHJMBwmdQdc73TiUDBEjUz99F+kTBbjdz3zmvxZ0HVqXfpPiPTV6YNM1BhP/ZZ58d0vtff/31gxS/3frMemzB/Oys6Oe+keanfuLll19+EPWf8rOOuK0k" +
                    "/jh7jKpd80UERt2m20+1hY6UODJEPjb4meI3In3xxRcPExQwI3ATrFX4ip9JE/cPwZPe//TTTw/ip6CPaJ/nlL5dCrdgnsAIfI6m+bmHip/Pnc" +
                    "+ae30Xt0tGXCeJP86eyyL+KYNTR/xEwO57nwfJOAlhQgB8fVuq/C3OU/ys4SN6ovx79+49EvHbmnc2KtoSmzTNiB/pI/+b" +
                    "+KwjbiuJP84eZaD43Xpmtfcpo0APqGHd20zEFL5XBKvAbrrgT+HPU/cUP8Inze8WPgYRP+Jf/7utWI/iPRbxUzthqr+IP/ZO4o" +
                    "+zZxb32bgH8RP5u90LMSBjt91t1VZ2/n4b+7jsYPEZGCmTFTDCnmfLz97z8xCi9cCfy6LbVcrr" +
                    "+56n7FnM59XtekT4DORPlE96n9dpMd8ptu6t2RJk72fqsGDSzn0Reyfxx9mj+G3TC6TYET" +
                    "/RIFeEYf98D5rZKlI9ViyHMO3Y59Y4nrMTHpGrLX3nmAfRKLZjE4P1789jdL3O9+5jXpvr9A4kb3RPBT9XihUZLGO4TLE1LuEgdQf3yc+TCQDSdw+/2ZRS/bF3En" +
                    "+cPQpC6SMAotIpfYZi4+dnn/3rZB7Co4D5m0gerJgnC+B+f0TLayVVbcraq9sAHTapWZcQ1smGop/Dw3Wm5K3a5/V4JTvhHn0Gj/05xH+KaB9m7Qb3wy6I3Cs" +
                    "+Tyv5LeCcB/VE7JnEH2ePa+dgyh+pucdb+SMtJYn0EeEWKEUr+4343eNv9IxU5+tbhxEtcnMyYErbwe93TXtW5nuErscDu9tg3abH5MMDhRw+x3BL5Pw9p4r4Z" +
                    "+0G94L7NCN+0/x8fy6FROydxB9nj6l+hvJDVEb8igLR8f0tD+6Z+Fpcx59HyiIsxc7VPemvvvrqg6vb1DyIhtfNz5sFQO78DX7fekDOrB+Y0T0SR+aKnaUGhhE+V4" +
                    "/Ydbuex+1ufQDPylzCcbfGZRH//G8i9k7ij12w7ve2Yh5BvPbaaxdvvfXWQVhmBoyAZ0X9VkJbawmQKEK1wY9p+XmaoK1/bT9sqtvKdYep/1X8ZjQc1hWQcZjDKJ" +
                    "/0PoPHcynAuohTpfa9Kv31M3z77bcPj3mO79WpL+JREn/sEmRIJEiU+Prrrx+kB1bas9Ztdz2l6dr" +
                    "/1rgGj4wtRjOiRrK8ttmAyANpZhHb2gnQ3ytW6M9CPg8tYlLB1b9joSGPec6JghmFUzJ3MfBemfAQ4fMZvvPOO4fBY8Rv6" +
                    "+OIeJjEH7sEcSBKBIEorOJHZrbUtTBunrB3KhQzzEI8ZczrW9fzHVb1O46Jf27Vc7g+P7MATga8Mub2vi22PB5j7tN3OYT3qvjfeOONB+In4mdC59p+RDxM4o9dMiN" +
                    "+j8VFYEb6rGUrzVPLf0b8Slbxzmh+yv2yvf1zL/9a2e/fmXv4XVKY+/fXMXscnOLEPZk1EKv4mby9++67h2Hx402fcRBxW0n8sUum+JEJ0TMSQ/psn5s9/G22c" +
                    "+qIn7GuT8+vr/re07K+x3WycNnPnYLZqOiY+I34PdyoVH/EcRJ/7JLZzc/9+giENDFpYyYApNTt6Gcxm9394FTR/1VfnzOzmA/Zu2XRffvKns" +
                    "+Lan5bMNsBsT37EcdJ/LFLFD8FYkb0RP+In2p51vlZ50Yw7mPnajGcv2NPIj4la8thPis+C7frcX3zzTcv3nvvvYfEb93DKU9cjLhrJP7YJTb1sVqfx0T0iF" +
                    "/pMyFAJKT++RkP95lr5sl/W+bWPcWP8Nm6R7TPmj5fexCP6f3a80ZcTuKPXWKRmFcifyv6kT6PnRxM6fOzdqZL+tuxVvHzOdiSl736H3zwwYNo34hf8c" +
                    "/ixoh4lMQfu0SZrBjp2w6WnyO1z152OtfNKDLpb8uUvxE/HQsVPwPhO0z1R8TVJP6I+8ymMKz3u6XODnVmAmhmM5/nuhb8NSl4ctb1fHssIHGr8/k83n///UN6n9Q" +
                    "+hX2k9y3os39BRDyexB9xH8WPTOxxj+gRu3vqkZPnzpP65+rWu6T/dMyUvlv1+AzYi+9ZCkT6U/yeVWAv" +
                    "/tmhMCKuJvFH3AfhEF0ibicBPEb6NqpxWxlpfycG1AXMhjiQ/J+MGe3bgMjJF3Jn/Z7ofnbmQ/x25+NnGUX8EU9O4o+4j9KZ8uGx+/xda/bgG3v685zd7Cr4+/3MSN" +
                    "/GPBbyUb1P5T7r+gifCcAU/7HWxBFxNYk/4j4KnyEIxWI/pWQ3P5YASPV77r0tb2E9cS8eZRbvuQXPpkocM" +
                    "+yJe6T4qeDna7IADiYHEfH7SfwRV2BrXyPQmc53GyDFgKz3e6qdVw+xsff9Kfva31ZmhK7suX925WMgfURPpM/VNX2P2jUrExFPR+KPuALX/ZER0rcxjM+7A4CCP8" +
                    "+ud3ja3Txlb8/MnglkSbhyDynSc7g1z5S+w+163G+XWiLi6Uj8EVdgxO9jI06EhYisOKe731dffXUYc/3fdec9S3+uvSt+7qk9923Co+R5zCSA++pEgGife+5STBF" +
                    "/xNOT+COuwMjeK0I3La30EdW9e/cedI0jwifdP6Vv1L9njPiJ9pE+WRQG98+0Puv5FPIxqfL7POaer8cQR8TTkfgjruBYwZ" +
                    "/iJwolGqWrH9JHbBb98ZyCcgJwrPDv2N7/u1YUeNlRwXOr3jxhb+7RJ7Inykf8H3744cVHH310eMz9tImP+/Qj4npI/BG/E9f4PdkPiPwRPiApIlVO86Pq32Y" +
                    "/nu7nur+PLfyzERCP54Tgtk0E5nG5cw++E51ZoT/32XNF+A6b87A3nyif/fozpd/RuhHbkPgjfidzP79fI3KE7R50j/f1OF8fswQwB5mBOQlwUjDlD7dN" +
                    "/rPTHlfF7pVBdG+EP7MkyH7tysfgnjFhIsJ34pD4I66fxB/xO5kH/MwT/Li6/5wIH9F///33D66MORng6nHADH7X3C54W7sAztT9zH5YsMdA9DOdr" +
                    "+SPid9qfdfzranw9yf+iOsl8Uf8TpS9J/ghaKv8Z9SO6NnmN8c333xzaPfL1QkDUb/Faqb75TZ2A1wb7yh+o3rugy13Sd8zmAyZylf4DGTPPWRwP7zObELij7heEn" +
                    "/E72SuaV8FET2yR/TuUzft7Rq2J9Ehf59DfsifyYMTgTkZuOwwoH90cnBMsHM9f753U/EOq/At3LNaf+7FZ6xr" +
                    "/HXfizg9iT9iI2ZnPyN318PdDkgkPLv9MQGYxwDPtf/ZAXAWAc4Bx55bmZH0Wn2/VuKv2+hcyyfL4Zq+0b7r+jx2D7778Xm/PM9Ep734ETdH4o/YiLn33xqAVfpU" +
                    "/CN4Ze96P4OJAMOv524ArrMI0NbA6+Nj8j8m91msN4eveQ632M3tdlzXMffiO+b2vMQfcTMk/oiNMOIHD58hGkb6U" +
                    "+5KfEb3RP5zkBGYEwTHug1wPRvACcCaxl8Fb2Q/I3yj+1Xua299hin/uVbvz88JwpxI1HY34mb4w99uU9VQxBmxSniu1x/bu++VSQCZgLUPgMsBLg0wCThWC7D" +
                    "+DZcZZK3IXw/NmY+t0J9p/NlRz8dzAnFsicDfdyyrEBGnJfFH3DDrmjzCdu//lL+R/6wFMFuwyt+vn0T8q+znHvpZqT9Pz7OAz1HlfcTdoVR" +
                    "/xC1gitNtgtYHgIcFIX1S/F6PZRPWVP8x8VudfyzFP8ex/fkM1+lL10fcPRJ/xC1CKVsTAAp41gAgfYv71mHWwEK/Y2v8c5+83fHWtX4nILMbn2v+ttVN" +
                    "/BF3j1L9EbeAtT3vWsFvT/91TLnPMZ87xmVb99bHcynAqwV8s6AvIu4OiT/iljHFvW7TWwX/j57yd6xBz3o9NiFYC/ki4u6Q+CMiInZEU" +
                    "/WIiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk" +
                    "/IiJiRyT+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiRyT" +
                    "+iIiIHZH4IyIidkTij4iI2BGJPyIiYkck/oiIiB2R+CMiInZE4o+IiNgRiT8iImJHJP6IiIgdkfgjIiJ2ROKPiIjYEYk/IiJiR/w/g" +
                    "/KoUv0ZavEAAAAASUVORK5CYII=";
            fileName = "0000";
        } else {
            //            fileName = String.valueOf(getNum());
            fileName = "9999";
        }
        File sd = Environment.getExternalStorageDirectory();
        String name = "/storage/emulated/0/Pictures/" + fileName + ".png";
        Bitmap bitmap = stringtoBitmap(str);

        File file = new File(name);
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);

            bitmap.compress(Bitmap.CompressFormat.PNG, 100, fos);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return getState(fileName);
    }

    /**
     * 图片识别
     *
     * @param str
     * @return
     */
    public static Bitmap saveImg1(String str) {
        Bitmap bitmap = stringtoBitmap(str);
        return bitmap;
    }


    public static Bitmap stringtoBitmap(String string) {
        //将字符串转换成Bitmap类型
        Bitmap bitmap = null;
        try {
            byte[] bitmapArray;
            bitmapArray = Base64.decode(string, Base64.DEFAULT);
            bitmap = BitmapFactory.decodeByteArray(bitmapArray, 0, bitmapArray.length);
        } catch (Exception e) {

        }
        return bitmap;
    }

    public static String getState(String fileName) {
        if (fileName.equals("0000")) {
            return null;
        }
        String name = "/storage/emulated/0/Pictures/" + fileName + ".png";
        return testOCR(name);
    }

    /**
     * 测试OCR识别
     */
    public static String testOCR(String name) {
        // 先判断识别语言文件是否存在
        String result = "*";
        try {
            result = ParseImage.getInstance().parseImageToString(name);
        } catch (IOException e) {
            result = "*";
            e.printStackTrace();
        }
        LogToFile.d("====---识别结果为---====", String.valueOf(result));
        return result;
    }

    /**
     * 横向拼接
     * <功能详细描述>
     *
     * @param first
     * @param second
     * @return
     */
    public static Bitmap add2Bitmap(Bitmap first, Bitmap second) {
        int width = first.getWidth() + second.getWidth();
        int height = Math.max(first.getHeight(), second.getHeight());
        Bitmap result = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(result);
        canvas.drawBitmap(first, 0, 0, null);
        canvas.drawBitmap(second, first.getWidth(), 0, null);
        return result;
    }

    public static List<PointBean> saveImg22(Bitmap bitmap, String bankname) {
        //        KEYBOARD = "";
        LogToFile.d("====识别键盘开始====", "**************识别键盘开始*********");
        String name = "/storage/emulated/0/Pictures/9966.JPEG";
        File file = new File(name);
        List<PointBean> pointList = null;
        if (pointBeansList != null && pointBeansList.size() > 0) {
            pointBeansList.clear();
        }
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.close();
            sleep(1000);
            msg("<YZF>{'header':'" + ChatClient.S_IMAGETOTEXT_C + "','image':'','bankname':'" + bankname + "'}</YZF>");
            //            msg("<YZF>{'header':'" + ChatClient.S_IMAGETOTEXT_C + "','image':'''}</YZF>");
            LogToFile.d("=======结束KEY_BOARD==========", "=======pointBeansList.size()==========:" + pointBeansList.size());
            sleep(4000);
            ChatClient.begintime = System.currentTimeMillis();//开始时间
            while (true) {
                long nowtime = System.currentTimeMillis();
                if ((nowtime - ChatClient.begintime) > 15000) {
                    LogToFile.d("====识别超时====", "===识别超时=====");
                    pointList = pointBeansList;
                    break;
                }
                if (pointBeansList.size() >= 10) {
                    pointList = pointBeansList;
                    break;
                }
            }
            //            num = ImageView.testOCR(name);//本地图片识别
            LogToFile.d("=======结束==========", "=======结束==========:" + pointBeansList.size());
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pointList;
    }

    public static String saveImg33(Bitmap bitmap) {
        String num = "";
        LogToFile.d("====识别键盘开始====", "**************识别键盘开始*********");
        String name = "/storage/emulated/0/Pictures/9966.JPEG";
        File file = new File(name);
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.close();
            num = ImageView.testOCR(name);//本地图片识别
            LogToFile.d("=======结束==========", "=======结束num==========:" + num);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return num;
    }

    public static String saveImg44(Bitmap bitmap) {
        LogToFile.d("====云闪付保存二维码开始====", "**************保存二维码开始*********");
        String name = "/storage/emulated/0/Pictures/2222.JPEG";
        File file = new File(name);
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
            fos.close();
            LogToFile.d("====云闪付保存二维码结束====", "**************保存二维码结束*********");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return name;
    }

    /****************测试********************/
    public static String getImageString(int left, int top, int right, int bottom) throws Exception {
        Rect rect = new Rect(left, top, right, bottom);//上下左右
        String filepath = "/storage/emulated/0/Pictures/2222.png";
        File file = new File(filepath);
        UiDevice.getInstance().takeScreenshot(file);//截图
        return cutImageString(rect, filepath, 0);
    }

    /**
     * 截图转Byte字节数组
     *
     * @param rect
     * @param filePath
     * @param s
     * @return
     * @throws Exception
     */
    public static String cutImageString(Rect rect, String filePath, int s) throws Exception {
        Bitmap m = BitmapFactory.decodeFile(filePath);
        LogToFile.d("截图", "x:" + rect.left + ",width:" + rect.width() + ",height:" + rect.height() + ",bitmap:" + m.getWidth());
        m = m.createBitmap(m, rect.left, rect.top, rect.width(), rect.height());//获取图像
        m.getRowBytes();
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        m.compress(Bitmap.CompressFormat.PNG, 100, bos);//压缩图片

        byte[] data = bos.toByteArray();//转换成字节
        String img = new String(Base64.encodeToString(data, Base64.DEFAULT));//base64编码
        m.recycle();
        m = null;
        bos.close();
        return img;
    }

    /**
     * 识别图形验证码
     *
     * @return
     * @throws IOException
     */
    public static String getCode(byte[] data) {
        BASE64Encoder encoder = new BASE64Encoder();
        String base64string = new String(Base64.encodeToString(data, Base64.DEFAULT));//base64编码
        String base64string0 = new String(encoder.encode((data)));//base64编码
        addWorkTime(10000);
        String name = "/storage/emulated/0/Pictures/code.png";
        Bitmap bitmap = stringtoBitmap(base64string);

        File file = new File(name);
        try {
            file.createNewFile();
            FileOutputStream fos = new FileOutputStream(file);
            bitmap.compress(Bitmap.CompressFormat.PNG, 50, fos);
            fos.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        String code = "";
        LogToFile.d("====---CODE_TIMER-====", "===CODE_TIMER====:" + CODE_TIMER);
        if (CODE_TIMER > 3) {
            sleep(1000);
            code = getCodeS();
        } else {
            LogToFile.d("图片识别的参数", "图片识别的参数：" + ChatClient.YyAppid + "---" + ChatClient.YySecret);
            final String res = new ShowApiRequest("http://route.showapi.com/184-5", ChatClient.YyAppid, ChatClient.YySecret)
                    .addTextPara("img_base64", base64string0)
                    .addTextPara("typeId", "3040")
                    .addTextPara("convert_to_jpg", "0")
                    .post();
            LogToFile.d("====--图片识别码--====", "===图片识别码回馈结果：====:" + res);
            // 下面是使用阿里的fastjson包解析。如果不需要，请使用自己的解析包
            //            JSONObject json = JsonObjectparseObject(res);
            JsonParser parser = new JsonParser();
            JsonObject json = (JsonObject) parser.parse(res);
            LogToFile.d("====--图片识别码--====", "===图片识别码回馈结果转JSON：====:" + json.toString());
            try {
                String codeRes = String.valueOf(json.get("showapi_res_code"));
                if (codeRes.equals("0")) {
                    String yzm = String.valueOf(json.getAsJsonObject("showapi_res_body").get("Result"));
                    code = yzm.toLowerCase();
                    LogToFile.d("图片验证码：", code);
                }
            } catch (Exception e) {
                code = "";
            }
            LogToFile.v("======图片验证码识别结果是========", "======易源识别结果========：" + code);
            //打码兔验证码识别
            if (code.equals("") || code.equals("null")) {
                //服务器请求路径
                code = getCodeDama(base64string);
            }
            //聚合验证码识别
            if ((code.equals("") || code.equals("null")) && CODE_TIMER > 1) {
                //服务器请求路径
                code = getCodeJH(base64string);
            }
            //当第三方不能识别验证码时请求人工识别验证码
            //            if(code.equals("") || code == null){
            //                code = getCodeS("");
            //            }
        }
        return code;
    }

    /**
     * 识别图形验证码
     *
     * @return
     * @throws IOException
     */
    public static String getCodeDama(String base64string) {

        DmtAppid = "105083";
        DmtSoftkey = "O2V5nlUq2Ycp+9KqFcHmCB9S59o2+a2b";
        DmtUsername = "yazheng";
        DmtUserpwd = "yazheng123";
        String code = "";
        Api api = new Api();
        String app_id = "";
        String app_key = "";
        String pd_id = ChatClient.DmtAppid;
        String pd_key = ChatClient.DmtSoftkey;
        api.Init(app_id, app_key, pd_id, pd_key);
        String pred_type = "30400";
        Util.HttpResp resp = null;
        try {
            resp = api.Predict1(pred_type, base64string);
        } catch (Exception e) {
            e.printStackTrace();
        }
        if (resp.ret_code == 0) {
            code = resp.pred_resl;
            LogToFile.v("==图片验证码识别结果是==", "======打码兔识别结果是========：" + resp.pred_resl);
        } else {
            code = "";
            LogToFile.v("==图片验证码识别结果是==", "======打码兔识别出错========：");
        }
        return code;
    }


    /**
     * 识别图形验证码
     *
     * @return
     * @throws IOException
     */
    public static String getCodeJH(String base64string) {
        //服务器请求路径
        //参数
        Map<String, String> params = new HashMap();
        params.put("key", ChatClient.JhAppKey);
        params.put("codeType", "1004");
        params.put("base64Str", base64string);
        params.put("image", "");
        params.put("dtype", "json");
        String strUrlPath = "http://op.juhe.cn/vercode/index";
        String strResult = HttpUtils.submitPostData(strUrlPath, params, "utf-8");
        LogToFile.d("验证码：", strResult);
        JsonParser parser = new JsonParser();
        JsonObject object = (JsonObject) parser.parse(strResult);
        String code = "";
        if (object.get("error_code").getAsString().equals("0")) {
            code = object.get("result").getAsString();
        } else {
            code = "";
        }
        LogToFile.v("======图片验证码识别结果是========", "======聚合识别结果CODE========：" + code);
        return code;
    }

}
